package com.eigaland.change_machine.customview

import android.content.Context
import android.graphics.Bitmap
import android.graphics.Color
import android.graphics.drawable.BitmapDrawable
import android.os.Parcel
import android.os.Parcelable
import android.util.AttributeSet
import android.util.Log
import android.view.Gravity
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.appcompat.widget.AppCompatTextView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.SimpleTarget
import com.eigland.eigaland_lib.model.Seat
import com.google.gson.Gson
import movie6.posprintercept2.extensions.dip
import movie6.posprintercept2.extensions.setBackgroundColorWithDefault
import movie6.posprintercept2.extensions.sp
import java.util.logging.Logger

public class SeatView(seat: Seat,context: Context?, attrs: AttributeSet?) : AppCompatTextView(context, attrs){



    init {
        layoutParams = ViewGroup.LayoutParams(dip(seat!!.w!!), dip(seat.h!!))
        x = dip(seat.x).toFloat()
        y = dip(seat.y).toFloat()
        text = seat.text
        gravity = Gravity.CENTER

        // text size
        textSize = 20f

        // text color


        when (seat.availability) {

            Seat.Availability.Available.s,
            Seat.Availability.OC.s ->
            {
                setTextColor(Color.parseColor(seat.color))

                setBackgroundColorWithDefault(seat.bgColor,Color.LTGRAY)
            }

            /*Seat.Availability.VIP.s -> {
                setTextColor(Color.parseColor(seat.color))  //
                setBackgroundColorWithDefault(congestionLevel.lv7ColorCode!!, Color.LTGRAY)
            }*/

            Seat.Availability.Reserved.s     -> {
                setTextColor(Color.parseColor(seat.colorReserved))
                setBackgroundColorWithDefault(seat.bgColorReserved, Color.LTGRAY)
            }
            Seat.Availability.Sold.s         -> {
                setTextColor(Color.parseColor(seat.colorSold))
                setBackgroundColorWithDefault(seat.bgColorSold, Color.DKGRAY)
            }
            Seat.Availability.NotAvailable.s -> {
                setTextColor(Color.parseColor(seat.colorSold))
                setBackgroundColorWithDefault(seat.bgColorSold, Color.DKGRAY)
            }


            else         -> {
                if (seat.isSelected) {
                    setTextColor(Color.parseColor(seat.colorSelected))
                    setBackgroundColorWithDefault(seat.bgColorSelected, Color.RED)
                } else {
                    setTextColor(Color.parseColor(seat.color))
                    setBackgroundColorWithDefault(seat.bgColor, Color.GREEN)
                }
            }
        }




    }
}
